package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

class zfz {
   private static final com.aspose.cells.b.c.a.za a = new com.aspose.cells.b.c.a.za(new String[]{"FONT-WEIGHT", "FONT-STYLE", "TEXT-DECORATION", "FONT-FAMILY", "COLOR", "BACKGROUND-COLOR", "FONT-SIZE", "UNDERLINE", "LINE-THROUGH", "X-SMALL", "XX-SMALL", "SMALL", "MEDIUM", "LARGE", "X-LARGE", "XX-LARGE", "PX", "PT", "IN", "CM", "SIZE", "FACE", "P", "OL", "UL", "LI", "TD", "FONT", "SPAN", "B", "STRONG", "I", "U", "S", "STRIKE", "SUP", "SUB", "BR"});

   private static String a(Style var0, int var1, Font var2) {
      StringBuilder var3 = new StringBuilder();
      if (var2.isBold()) {
         var3.append("FONT-WEIGHT: bold;");
      }

      if (var2.isItalic()) {
         var3.append("FONT-STYLE: italic;");
      }

      if (var2.getUnderline() != 0 || var2.isStrikeout()) {
         var3.append("TEXT-DECORATION:");
         if (var2.getUnderline() != 0) {
            var3.append(" underline");
            if (var2.isStrikeout()) {
               var3.append(" line-through;");
            } else {
               var3.append(";");
            }
         } else if (var2.isStrikeout()) {
            var3.append(" line-through;");
         }
      }

      var3.append("FONT-FAMILY: " + var2.getName() + ";");
      var3.append("FONT-SIZE: " + com.aspose.cells.b.a.zn.b(var2.getDoubleSize()) + "pt;");
      var3.append("COLOR: #" + com.aspose.cells.a.c.zp.c(com.aspose.cells.a.c.zh.b(var2.getColor()) & 255) + com.aspose.cells.a.c.zp.c(com.aspose.cells.a.c.zh.c(var2.getColor()) & 255) + com.aspose.cells.a.c.zp.c(com.aspose.cells.a.c.zh.d(var2.getColor()) & 255) + ";");
      String var4 = null;
      switch(var1) {
      case 1:
         var4 = "center;";
         break;
      case 7:
         var4 = "left;";
         break;
      case 8:
         var4 = "right;";
      }

      if (var4 != null) {
         var3.append("TEXT-ALIGN: " + var4);
      }

      if (var0 != null && var0.getPattern() == 1 && !var0.b.a()) {
         Color var5 = var0.getForegroundColor();
         var3.append("Background-Color: #" + com.aspose.cells.a.c.zp.c(com.aspose.cells.a.c.zh.b(var5) & 255) + com.aspose.cells.a.c.zp.c(com.aspose.cells.a.c.zh.c(var5) & 255) + com.aspose.cells.a.c.zp.c(com.aspose.cells.a.c.zh.d(var5) & 255) + ";");
      }

      return com.aspose.cells.b.a.zr.a(var3);
   }

   private static void a(zcfx var0, String var1, int var2, int var3) throws Exception {
      char[] var4 = var1.toCharArray();
      StringBuilder var5 = new StringBuilder();
      boolean var6 = true;

      for(int var7 = var2; var7 <= var3; ++var7) {
         if (var4[var7] != '\r') {
            if (var4[var7] == '\n') {
               var6 = true;
               var0.a(com.aspose.cells.b.a.zr.a(var5));
               var0.d("<Br>");
               var5.delete(0, 0 + var5.length());
            } else if (var4[var7] == ' ') {
               if (var6) {
                  var0.d("&nbsp;");
               } else {
                  var5.append(var4[var7]);
               }
            } else {
               var6 = false;
               var5.append(var4[var7]);
            }
         }
      }

      if (var5.length() != 0) {
         var0.a(com.aspose.cells.b.a.zr.a(var5));
      }

   }

   static String a(Cell var0) throws Exception {
      Style var1 = var0.p();
      com.aspose.cells.b.a.d.zh var2 = new com.aspose.cells.b.a.d.zh();
      zcfx var3 = new zcfx(var2, Encoding.getUTF8());
      String var5;
      if (var0.I()) {
         FontSetting[] var4 = var0.getCharacters();
         var5 = ((zbap)var0.c.d).c;

         for(int var6 = 0; var6 < var4.length; ++var6) {
            FontSetting var7 = var4[var6];
            var3.b("Font");
            String var8 = a(var1, var1.getHorizontalAlignment(), var7.getFont());
            var3.a("Style", var8);
            if (var7.getFont().isSuperscript()) {
               var3.b("Sup");
            }

            if (var7.getFont().isSubscript()) {
               var3.b("Sub");
            }

            a(var3, var5, var7.getStartIndex(), var7.getStartIndex() + var7.getLength() - 1);
            if (var7.getFont().isSuperscript()) {
               var3.b();
            }

            if (var7.getFont().isSubscript()) {
               var3.b("Sub");
            }

            var3.b();
         }
      } else {
         var3.b("Font");
         String var9 = a(var1, var1.getHorizontalAlignment(), var1.getFont());
         var3.a("Style", var9);
         if (var1.getFont().isSuperscript()) {
            var3.b("Sup");
         }

         if (var1.getFont().isSubscript()) {
            var3.b("Sub");
         }

         var5 = var0.j();
         a(var3, var5, 0, var5.length() - 1);
         if (var1.getFont().isSuperscript()) {
            var3.b();
         }

         if (var1.getFont().isSubscript()) {
            var3.b("Sub");
         }

         var3.b();
      }

      var3.e();
      var3.f();
      var2.a();
      byte[] var10 = var2.o();
      return Encoding.getUTF8().a(var10, 3, var10.length - 3);
   }

   static String a(zbtz var0) throws Exception {
      int var1 = var0.g();
      com.aspose.cells.b.a.d.zh var2 = new com.aspose.cells.b.a.d.zh();
      zcfx var3 = new zcfx(var2, Encoding.getUTF8());
      if (var0.s() != null) {
         ArrayList var4 = var0.s();
         String var5 = var0.i();

         for(int var6 = 0; var6 < var4.size(); ++var6) {
            FontSetting var7 = (FontSetting)var4.get(var6);
            var3.b("Font");
            String var8 = a((Style)null, var1, var7.getFont());
            var3.a("Style", var8);
            var3.a(var5.substring(var7.getStartIndex(), var7.getStartIndex() + var7.getLength()));
            var3.b();
         }
      } else {
         var3.b("Font");
         String var9 = a((Style)null, var1, var0.k());
         var3.a("Style", var9);
         var3.a(var0.i());
         var3.b();
      }

      var3.e();
      var3.f();
      var2.a();
      byte[] var10 = var2.o();
      return Encoding.getUTF8().a(var10, 3, var10.length - 3);
   }

   static void a(WorksheetCollection var0, Font var1, HashMap var2, HashMap var3) {
      String var4 = (String)var2.get("STYLE");
      int var9;
      if (var4 == null) {
         Iterator var17 = var2.keySet().iterator();

         while(var17.hasNext()) {
            String var18 = (String)var17.next();
            Object var19 = var2.get(var18);
            switch(a.a(var18.toUpperCase())) {
            case 4:
               var1.setColor(com.aspose.cells.b.a.b.zf.a((String)var19));
               break;
            case 20:
               var1.setDoubleSize(com.aspose.cells.b.a.zn.a((String)var19));
               break;
            case 21:
               String var21 = (String)var19;
               var9 = var21.indexOf(44);
               if (var9 == -1) {
                  var1.b(var21);
               } else {
                  var1.b(var21.substring(0, 0 + var9).trim());
               }
            }
         }

      } else {
         String[] var5 = com.aspose.cells.b.a.zv.d(var4, ';');

         label112:
         for(int var6 = 0; var6 < var5.length; ++var6) {
            String[] var7 = com.aspose.cells.b.a.zv.d(var5[var6], ':');

            for(int var8 = 0; var8 < var7.length; ++var8) {
               var7[var8] = var7[var8].trim();
            }

            switch(a.a(var7[0].toUpperCase())) {
            case 0:
               var1.setBold("BOLD".equals(var7[1].toUpperCase()));
               break;
            case 1:
               var1.setItalic("ITALIC".equals(var7[1].toUpperCase()));
               break;
            case 2:
               String[] var20 = com.aspose.cells.b.a.zv.d(var7[1].toUpperCase(), ' ');
               var9 = 0;

               while(true) {
                  if (var9 >= var20.length) {
                     continue label112;
                  }

                  switch(a.a(var20[var9].trim())) {
                  case 7:
                     var1.setUnderline(1);
                     break;
                  case 8:
                     var1.setStrikeout(true);
                  }

                  ++var9;
               }
            case 3:
               var1.b(var7[1]);
               break;
            case 4:
               if (var7[1].toUpperCase().startsWith("RGB(")) {
                  String var22 = var7[1].substring(4, 4 + (var7[1].length() - 5));
                  String[] var23 = com.aspose.cells.b.a.zv.d(var22, ',');
                  var1.setColor(Color.fromArgb(com.aspose.cells.b.a.zo.a(var23[0].trim()), com.aspose.cells.b.a.zo.a(var23[1].trim()), com.aspose.cells.b.a.zo.a(var23[2].trim())));
               } else {
                  var1.setColor(com.aspose.cells.b.a.b.zf.a(var7[1]));
               }
               break;
            case 5:
               var3.put("BACKGROUND-COLOR", com.aspose.cells.b.a.b.zf.a(var7[1]));
               break;
            case 6:
               var9 = -1;
               String var10 = var7[1].toUpperCase();
               switch(a.a(var10)) {
               case 9:
                  var1.setSize(8);
                  break;
               case 10:
                  var1.setSize(10);
                  break;
               case 11:
                  var1.setSize(12);
                  break;
               case 12:
                  var1.setSize(14);
                  break;
               case 13:
                  var1.setSize(18);
                  break;
               case 14:
                  var1.setSize(24);
                  break;
               case 15:
                  var1.setSize(36);
                  break;
               default:
                  char[] var11 = var10.toCharArray();

                  for(int var12 = 0; var12 < var11.length; ++var12) {
                     if (!Character.isDigit(var11[var12]) && var11[var12] != '.' && var11[var12] != '+' && var11[var12] != '-') {
                        var9 = var12;
                        break;
                     }
                  }

                  String var24 = "PX";
                  double var13 = 0.0D;
                  if (var9 == -1) {
                     var13 = com.aspose.cells.b.a.zn.a(var7[1]);
                  } else {
                     var13 = com.aspose.cells.b.a.zn.a(var7[1].substring(0, 0 + var9).trim());
                     var24 = var7[1].substring(var9).trim();
                  }

                  double var15 = 0.0D;
                  switch(a.a(var24.toUpperCase())) {
                  case 16:
                     var15 = var13 * 72.0D / (double)var0.L();
                     break;
                  case 17:
                     var15 = var13;
                     break;
                  case 18:
                     var15 = var13 * 72.0D;
                     break;
                  case 19:
                     var15 = var13 * 72.0D / 2.54D;
                     break;
                  default:
                     var15 = var13;
                  }

                  var1.setDoubleSize(var15);
               }
            }
         }

      }
   }

   static void a(StringBuilder var0, HashMap var1) {
      String var2 = com.aspose.cells.b.a.zr.a(var0);
      if (!"".equals(var2)) {
         var0.delete(0, 0 + var0.length());
         if (var2.indexOf(61) != -1) {
            String[] var3 = com.aspose.cells.b.a.zv.d(var2, '=');

            for(int var4 = 0; var4 < var3.length; ++var4) {
               var3[var4] = var3[var4].trim();
               if (var3[var4].charAt(0) == '\'') {
                  var3[var4] = var3[var4].substring(1, 1 + (var3.length - 2));
               }

               if (var3[var4].charAt(0) == '"') {
                  var3[var4] = var3[var4].substring(1, 1 + (var3.length - 2));
               }
            }

            var1.put(var3[0].toUpperCase(), var3[1]);
         } else {
            var1.put(var2.toUpperCase(), true);
         }

      }
   }

   static String a(WorksheetCollection var0, Font var1, String var2, ArrayList var3, HashMap var4) {
      char[] var5 = var2.toCharArray();
      StringBuilder var6 = new StringBuilder();
      Font var7 = new Font(var0, (Object)null, false);
      var7.c(var1);
      int var8 = 0;
      boolean var9 = false;
      boolean var10 = false;
      ArrayList var11 = new ArrayList();
      ArrayList var12 = new ArrayList();

      for(int var13 = 0; var13 < var5.length; ++var13) {
         StringBuilder var15;
         if (var5[var13] == '<') {
            if (var5[var13 + 1] == ' ') {
               var6.append(var5[var13]);
            } else if (var5[var13 + 1] == '!' && var5[var13 + 2] == '-' && var5[var13 + 3] == '-') {
               for(var13 += 4; var13 < var5.length; ++var13) {
                  if (var5[var13] == '-' && var5[var13 + 1] == '-' && var5[var13 + 2] == '>') {
                     var13 += 2;
                     break;
                  }
               }
            } else if (var5[var13 + 1] == '?') {
               for(var13 += 2; var13 < var5.length; ++var13) {
                  if (var5[var13] == '/' && var5[var13 + 1] == '>') {
                     ++var13;
                     break;
                  }
               }
            } else {
               boolean var22 = var5[var13 + 1] == '/';
               if (var22) {
                  ++var13;
               }

               var15 = new StringBuilder();
               HashMap var23 = new HashMap();
               String var17 = null;
               ++var13;

               for(; var13 < var5.length && var5[var13] != '>'; ++var13) {
                  if (var5[var13] == '=') {
                     boolean var18 = false;
                     String var19 = com.aspose.cells.b.a.zr.a(var15).trim().toUpperCase();
                     var15.delete(0, 0 + var15.length());
                     ++var13;

                     for(; var13 < var5.length; ++var13) {
                        if (var5[var13] == '>') {
                           --var13;
                           break;
                        }

                        if (var5[var13] == ' ') {
                           if (!var18) {
                              break;
                           }
                        } else if (var5[var13] == '\'') {
                           ++var13;

                           while(var13 < var5.length && var5[var13] != '\'') {
                              var15.append(var5[var13]);
                              ++var13;
                           }

                           var18 = false;
                        } else if (var5[var13] != '"') {
                           var15.append(var5[var13]);
                           var18 = false;
                        } else {
                           ++var13;

                           while(var13 < var5.length && var5[var13] != '"') {
                              var15.append(var5[var13]);
                              ++var13;
                           }

                           var18 = false;
                        }
                     }

                     var23.put(var19, com.aspose.cells.b.a.zr.a(var15).trim());
                     var15.delete(0, 0 + var15.length());
                  } else if (var5[var13] == ' ') {
                     if (var15.length() > 0) {
                        if (var17 == null) {
                           var17 = com.aspose.cells.b.a.zr.a(var15).trim().toUpperCase();
                           var15.delete(0, 0 + var15.length());
                        } else {
                           a(var15, var23);
                        }
                     }
                  } else {
                     var15.append(var5[var13]);
                  }
               }

               if (var15.length() > 0) {
                  if (var17 == null) {
                     var17 = com.aspose.cells.b.a.zr.a(var15).trim().toUpperCase();
                     var15.delete(0, 0 + var15.length());
                  } else {
                     a(var15, var23);
                  }
               }

               int var25;
               ArrayList var29;
               if (var22) {
                  var29 = new ArrayList();
                  com.aspose.cells.b.a.a.ze.a(var29, (Object)var17);
                  ++var13;

                  while(var13 < var5.length) {
                     if (var5[var13] != '<' || var5[var13 + 1] != '/') {
                        --var13;
                        break;
                     }

                     for(var13 += 2; var13 < var5.length && var5[var13] != '>'; ++var13) {
                        var15.append(var5[var13]);
                     }

                     com.aspose.cells.b.a.a.ze.a(var29, (Object)com.aspose.cells.b.a.zr.a(var15).toUpperCase());
                     var15.delete(0, 0 + var15.length());
                     ++var13;
                  }

                  if (var8 != var6.length()) {
                     FontSetting var27 = new FontSetting(var8, var6.length() - var8, var0, false);
                     var27.getFont().c(var7);
                     com.aspose.cells.b.a.a.ze.a(var3, (Object)var27);
                     var8 = var6.length();
                  }

                  for(var25 = 0; var25 < var29.size(); ++var25) {
                     switch(a.a((String)var29.get(var25))) {
                     case 22:
                        var6.append('\n');
                        break;
                     case 23:
                     case 24:
                        var11.remove(var11.size() - 1);
                        if (var12.size() > var11.size()) {
                           com.aspose.cells.b.a.a.ze.a(var12, var11.size(), var12.size() - var11.size());
                        }
                        break;
                     case 25:
                        var6.append('\n');
                        break;
                     case 26:
                     case 27:
                        var7 = new Font(var0, (Object)null, false);
                        break;
                     case 28:
                        ArrayList var20 = (ArrayList)var4.get("SPANFONTS");
                        if (var20 != null && var20.size() > 0) {
                           Font var21 = (Font)var20.get(var20.size() - 1);
                           var20.remove(var20.size() - 1);
                           var7.c(var21);
                        }
                        break;
                     case 29:
                     case 30:
                        var7.setBold(false);
                        break;
                     case 31:
                        var7.setItalic(false);
                        break;
                     case 32:
                        var7.setUnderline(0);
                        break;
                     case 33:
                     case 34:
                        var7.setStrikeout(false);
                        break;
                     case 35:
                        var7.setSuperscript(false);
                        break;
                     case 36:
                        var7.setSubscript(false);
                     }
                  }
               } else if (var17 != null && !"".equals(var17)) {
                  if (var17.endsWith("/")) {
                     if (var17.startsWith("BR")) {
                        var6.append('\n');
                     }
                  } else {
                     switch(a.a(var17)) {
                     case 23:
                     case 24:
                        com.aspose.cells.b.a.a.ze.a(var11, (Object)var17);
                        break;
                     case 25:
                        int var24 = 1;
                        if (var11.size() > var12.size()) {
                           com.aspose.cells.b.a.a.ze.a(var12, (Object)var24);
                        } else if (var12.size() > 0) {
                           var24 = (Integer)var12.get(var12.size() - 1);
                           ++var24;
                           var12.set(var12.size() - 1, var24);
                        }

                        for(var25 = 0; var25 < var12.size(); ++var25) {
                           var6.append("    ");
                        }

                        if (var11.size() > 0 && "OL".equals((String)var11.get(var11.size() - 1))) {
                           var6.append(var24 + ".");
                           var6.append(" ");
                        }
                        break;
                     case 26:
                     case 27:
                     case 28:
                        var9 = true;
                        break;
                     case 29:
                     case 30:
                     case 31:
                     case 32:
                     case 33:
                     case 34:
                     case 35:
                     case 36:
                        var9 = true;
                        break;
                     case 37:
                        var6.append('\n');
                        continue;
                     }

                     if (!var10 && var8 != var6.length()) {
                        FontSetting var28 = new FontSetting(var8, var6.length() - var8, var0, false);
                        var28.getFont().c(var7);
                        com.aspose.cells.b.a.a.ze.a(var3, (Object)var28);
                        var8 = var6.length();
                     }

                     switch(a.a(var17)) {
                     case 26:
                        var7 = new Font(var0, (Object)null, false);
                        var7.c(var1);
                        a(var0, var7, var23, var4);
                        break;
                     case 27:
                        var7 = new Font(var0, (Object)null, false);
                        var7.c(var1);
                        a(var0, var7, var23, var4);
                        break;
                     case 28:
                        var29 = (ArrayList)var4.get("SPANFONTS");
                        if (var29 == null) {
                           var29 = new ArrayList();
                           var4.put("SPANFONTS", var29);
                        }

                        Font var26 = new Font(var0, (Object)null, false);
                        var26.c(var7);
                        com.aspose.cells.b.a.a.ze.a(var29, (Object)var26);
                        a(var0, var7, var23, var4);
                        break;
                     case 29:
                     case 30:
                        var7.setBold(true);
                        break;
                     case 31:
                        var7.setItalic(true);
                        break;
                     case 32:
                        var7.setUnderline(1);
                        break;
                     case 33:
                     case 34:
                        var7.setStrikeout(true);
                        break;
                     case 35:
                        var7.setSuperscript(true);
                        break;
                     case 36:
                        var7.setSubscript(true);
                     }

                     var10 = var9;
                  }
               }
            }
         } else if (var5[var13] != '&') {
            if (var5[var13] == '\r') {
               var10 = false;
               if (var13 + 1 < var5.length && var5[var13 + 1] == '\n') {
                  var6.append('\n');
                  ++var13;
               } else {
                  var6.append('\n');
               }
            } else {
               var10 = false;
               var6.append(var5[var13]);
            }
         } else {
            var10 = false;
            int var14 = var13;
            var15 = new StringBuilder();

            boolean var16;
            for(var16 = false; var13 < var5.length; ++var13) {
               var15.append(var5[var13]);
               if (var5[var13] == ';') {
                  var16 = true;
                  break;
               }
            }

            if (var16) {
               zadt.a(var6, var15);
            } else {
               var13 = var14;
               var6.append(var5[var14]);
            }
         }
      }

      FontSetting var30;
      if (var8 != var6.length()) {
         var30 = new FontSetting(var8, var6.length() - var8, var0, false);
         var30.getFont().c(var7);
         com.aspose.cells.b.a.a.ze.a(var3, (Object)var30);
         var8 = var6.length();
      }

      if (var6.length() > 0 && var6.charAt(var6.length() - 1) == '\n') {
         var6.delete(var6.length() - 1, var6.length() - 1 + 1);
         if (var3.size() > 0) {
            var30 = (FontSetting)var3.get(var3.size() - 1);
            if (var30.getStartIndex() + var30.getLength() > var6.length()) {
               var30.c(var6.length() - var30.getStartIndex());
               if (var30.getLength() < 0) {
                  var3.remove(var3.size() - 1);
               }
            }
         }
      }

      return com.aspose.cells.b.a.zr.a(var6);
   }

   static void a(Cell var0, String var1) {
      Style var2 = var0.getStyle();
      Font var3 = var2.getFont();
      var3.e(0);
      WorksheetCollection var4 = var0.d.r();
      ArrayList var5 = new ArrayList();
      HashMap var6 = new HashMap();
      String var7 = a(var4, var3, var1, var5, var6);
      if (var5.size() == 2) {
         FontSetting var8 = (FontSetting)var5.get(1);
         if (var8.getStartIndex() == var7.length()) {
            var5.remove(1);
         }
      }

      var0.a(var7, var5);
      if ((var2.getPattern() == 0 || var2.getPattern() == 1) && var6.get("BACKGROUND-COLOR") != null) {
         var2 = var0.getStyle();
         var2.setPattern(1);
         var2.setForegroundColor((Color)var6.get("BACKGROUND-COLOR"));
         var0.setStyle(var2);
      }

   }

   static void a(Shape var0, zbtz var1, String var2) {
      Font var3 = var1.k();
      WorksheetCollection var4 = var0.L();
      ArrayList var5 = new ArrayList();
      HashMap var6 = new HashMap();
      var1.a(a(var4, var3, var2, var5, var6));
      if (var5.size() != 0) {
         if (var5.size() == 1) {
            var1.k().c(((FontSetting)var5.get(0)).getFont());
         } else {
            var1.b(var5);
         }
      }

   }
}
